jQuery(function(){
	
	//获取合同列表页面数据 服务器分页
    var serverData = {};
    var serverTable;
    jQuery(document).ready(function () {

    	serverTable = jQuery('#dataTable').DataTable({
            "serverSide": true,
            "ordering": false,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url":window.rootPath+ '/ui/afterSalePlan/getpage',
                "data": function (d) {
                    return $.extend({}, d, serverData);
                }
            },
            columns: [
                {
                	data: null
                },
                {
    	            data: null,
    	            defaultContent: "",
    	            render: function (data, type, full, meta) {
    	            	var id=data.id
    	            	var operate ='<input type="checkbox" class="checkchildContract">';
    	            	return operate;
    	            }   
                },
                {
                    data: 'supplierCode'
                },
                {
                	data: 'projectName',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
						}
					}
                },
                {
                    data: 'orderUnit',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
						}
					}
                },
                {
                    data: 'scheduleDate',
                    render: function (data, type, full, meta) {
                        if (data)
                            return moment(data).format('YYYY/MM/DD');
                        else
                            return '';
                    }
                },
                {
                	data: 'memo',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
						}
					}
                }
                ],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
            }
        });
	
	///添加售后维护计划
	jQuery('.editBtn').on('click',function(){
		var selects=getSelect("#dataTable",1);
		if(selects.length>1){
			   $.springLemonDialog({
			         content: '只能编辑一条记录',// 确认文本
			         clickButton: function (sender, modal, index) {// 按钮事件处理
			             $(this).closeDialog(modal);
			         }
			   }); 
		   }
		   else if(selects.length==0){
			   $.springLemonDialog({
			         content: '请选择要编辑的记录',// 确认文本
			         clickButton: function (sender, modal, index) {// 按钮事件处理
			             $(this).closeDialog(modal);
			         }
			   }); 
		   }else if(selects.length==1){
			 var id = selects[0].id;
			 window.location = window.rootPath+"/ui/afterSalePlan/editPlan/"+id;
		   }
	})
	
	//查询
    jQuery('.searchBtn').on('click',function(){
        serverData.key=jQuery('#keyword').val();
        serverTable.draw();
    })
    
    //撤销查询
    jQuery('.resetBtn').on("click",function(){
        jQuery('#keyword').val('');
        serverData.key ='';
        serverTable.draw();
    });

	//列表中的全选
    $("#checkAllContract").click(function(){
    	var check = $(this).prop("checked");
        $(".checkchildContract").prop("checked", check);
	});
	
	
	
});
});